const vscode = acquireVsCodeApi();
let intervalInner = null
window.onload = e => {
    // 在 WebView 中
    window.addEventListener('message', event => {
        const message = event.data;
        switch (message.command) {
            case 'v2cGetEditorStoreRes':
                // 处理来自扩展的消息
                console.log(message.data);
                render(JSON.parse(message.data));
                break;
            // 处理其他消息...
        }
    });
};

function getProcess() {
    // 在 Webview 页面中
    // 发送消息给扩展，触发命令
    clearInterval(intervalInner)
    intervalInner = setInterval(() => {
        vscode.postMessage({ command: 'v2cGetEditorStore' });
    }, 1000);
}

function render(store) {
    // {"editorLength":0,"leftContentLength":1,"rightContentLength":1,"rightProgressLength":1,"rightProgress":"100.00"}
    document.getElementById('root').innerHTML = `
    左: </br>
    总字数:${store.leftContentLength}</br>
    总行数:</br>
    右:</br>
    总字数:${store.rightContentLength}</br>
    总行数:</br>

    进度字数:${store.rightProgressLength} </br>
    
    总进度:${store.rightProgress}%</br>
    `;
}